package com.mycompany.ui.panel.searches;


import java.util.List;
import java.util.ResourceBundle.Control;


import org.springframework.beans.factory.annotation.Autowired;

import com.jensjansson.pagedtable.ControlsLayout;
import com.jensjansson.pagedtable.PagedTable;

import com.mycompany.config.Injector;
import com.mycompany.customContainer.LazyLoadedContainer;


import com.mycompany.model.QUser;
import com.mycompany.model.User;
import com.mycompany.queryBuilder.QueryBuilder;
import com.mycompany.repositories.UserRepository;
import com.mysema.query.types.Predicate;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Button.ClickEvent;

public class UserSearchPanel extends Panel {
	
	private VerticalLayout verticalLayout;
	private TextField fieldRicercaUtente = new TextField("Ricerca Utente");
	private Label labelRisultatoRicerca = new Label();
	
	@Autowired
	UserRepository userRepository;
	
	public UserSearchPanel() {
		// TODO Auto-generated constructor stub
		Injector.inject(this);
		setSizeFull();
		
		setCaption("Tabella Paginata");
		
		verticalLayout = new VerticalLayout();
		verticalLayout.setMargin(true);
		
		
		//PagedTable pagedTable = new PagedTable();
		
		//LazyLoadedContainer lazyLoadedContainer = new LazyLoadedContainer(User.class);
		//pagedTable.setPageLength(5);
		//pagedTable.setContainerDataSource(lazyLoadedContainer);
        //pagedTable.setVisibleColumns(new Object[] { "id","nome", "cognome", "codiceFiscale", "email", "telefono" });
        //pagedTable.setSizeFull();
        
		//verticalLayout.addComponent(pagedTable);
		//ControlsLayout controlsLayout = pagedTable.createControls();
		
		//verticalLayout.addComponent(controlsLayout);
		verticalLayout.addComponent(createPanelFindUser());
		setContent(verticalLayout);
	
	}

	private Component createPanelFindUser() {
		// TODO Auto-generated method stub
		VerticalLayout verticalLayout = new VerticalLayout();
		verticalLayout.setSizeFull();
		verticalLayout.setMargin(true);
		verticalLayout.addComponent(fieldRicercaUtente);
		verticalLayout.addComponent(createButtonRicercaUtente());
		verticalLayout.addComponent(labelRisultatoRicerca);
		
		return verticalLayout;
		
	}

	private Component createButtonRicercaUtente() {
		
		Button button = new Button("Cerca");
		button.addClickListener(new ClickListener() {
			
			@Override
			public void buttonClick(ClickEvent event) {
				// TODO Auto-generated method stub
				QUser user2 = QUser.user;
				user2.nome.contains("Rino");
				User user = userRepository.findOne(user2.nome.contains("Rino"));
				System.out.println(user);
				
			}
		});
		
		return button;
	}

}
